import java.io.Serializable;
import java.util.List;

import javax.ejb.EJB;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ViewScoped;

import com.google.code.ptrends.Application.DAL.SessionServiceBean;
import com.google.code.ptrends.Application.DAL.entities.*;


@ManagedBean(name = "sessionBean")
@ViewScoped
public class SessionBean implements Serializable {

	private static final long serialVersionUID = 1L;

	@EJB
	transient SessionServiceBean beanService;

	private SessionEntity selectedSession = new SessionEntity();
	private SessionEventEntity selectedEvent = new SessionEventEntity();
	private List<SessionEntity> sessions;

	public SessionBean() {
	}

	public void setSelectedSession(SessionEntity selectedSession) {
		this.selectedSession = selectedSession;
	}

	public SessionEntity getSelectedSession() {
		return selectedSession;
	}

	public void setSessions(List<SessionEntity> sessions) {
		this.sessions = sessions;
	}

	public List<SessionEntity> getSessions() {
		if(this.sessions == null){
			loadData();
		}
		return sessions;
	}

	public void setSelectedEvent(SessionEventEntity selectedEvent) {
		this.selectedEvent = selectedEvent;
	}

	public SessionEventEntity getSelectedEvent() {
		return selectedEvent;
	}

	private void loadData() {
		this.sessions = beanService.getAllSessionsWithoutEvents();
	}

}
